package flag

import (
	"blog_go/global"
	"blog_go/models"
	"blog_go/plugins/log_stash"
)

func Makemigrations() {
	var err error
	// 第一个参数为具有连接另一个表的字段的连接表,第二个即为连接字段的字段,第三个为连接表
	global.DB.SetupJoinTable(&models.UserModel{}, "CollModels", models.User2CollModel{})
	global.DB.SetupJoinTable(&models.MenuModel{}, "ImageList", models.Menu2ImageModel{})
	global.DB.SetupJoinTable(&models.ArticleModel{}, "TagModels", models.Article2TagModel{})
	err = global.DB.Set("gorm:table_options", "ENGINE=InnoDB").AutoMigrate(
		&models.ImageModel{},
		&models.TagModel{},
		&models.MessageModel{},
		&models.AdvertModel{},
		&models.UserModel{},
		&models.CommentModel{},
		&models.ArticleModel{},
		&models.MenuModel{},
		&models.FadeBackModel{},
		&models.LoginDataModel{},
		&models.ChatModel{},
		&log_stash.LogStashModel{},
	)
	if err != nil {
		global.Log.Error(err)
		return
	}
	global.Log.Info("表结构生成成功")
}
